package com.jsr;

import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import java.util.Set;

/**
 * @Author: xgs
 * Description:  注解处理器
 *  @SupportedAnnotationTypes  处理器支持的注解名称
 *  @SupportedSourceVersion 处理器支持的源码编译版本
 *
 * @Date: 2022/11/23/11:18
 */
@SupportedAnnotationTypes("com.jsr.demo1.SayHello")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class SayHelloProcessor extends AbstractProcessor {


    @Override
    public synchronized void init(ProcessingEnvironment processingEnv) {
        super.init(processingEnv);
    }

    @Override
    public SourceVersion getSupportedSourceVersion() {
        return SourceVersion.latest();
    }


    /**
     * {@inheritDoc}
     *
     * @param annotations
     * @param roundEnv
     */
    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        if (!roundEnv.processingOver()) {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Hello World!");
        }
        return true;
    }
}
